package jdbc2;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
/*
* 关联查询
* */
public class JDBCDemo6 {
    public static void main(String[] args) {
        try (Connection conn = DBUtil.getConnection()){
            Statement stmt = conn.createStatement();
            /*
            * 查看每个班级以及对应班主任的信息
            *SELECT c.name,c.floor,t.name,t.title,t.salary FROM class c JOIN teacher t
            * ON c.teacher_id = t.id;
            * */
            String sql = "SELECT c.name,c.floor,t.name,t.title,t.salary FROM class c JOIN teacher t \n" +
                    " ON c.teacher_id = t.id;";
            ResultSet rs = stmt.executeQuery(sql);
            while (rs.next()){
                String cName = rs.getString(1);
                int cFloor = rs.getInt(2);
                String tName = rs.getString(3);
                String tTitle = rs.getString(4);
                int tSalary = rs.getInt(5);
                System.out.println(cName + " " + cFloor + " " + tName + " " + tTitle + " " + tSalary);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
